//
//  CCDirectorPrism.mm
//  Prism
//
//  Created by Bas du Pre on 22-05-11.
//  Copyright 2011 UU. All rights reserved.
//

#include "global.h"
#if PRISM_OS_IOS

#import "CCDirector.h"
#import "CCDirectorIOS.h"

#import "CCDirectorPrism.h"

#include "Director.h"

@implementation CCDirectorIOS (CCDirectorPrism)

//
// Draw the Scene
//
- (void) drawScene
{    
	/* calculate "global" dt */
    [self performSelector:@selector(calculateDeltaTime)];
	
	/* tick before glClear: issue #533 */
	if( ! isPaused_ ) {
		[[CCScheduler sharedScheduler] tick: dt];	
	}
	
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	/* to avoid flickr, nextScene MUST be here: after tick and before draw.
	 XXX: Which bug is this one. It seems that it can't be reproduced with v0.9 */
	if( nextScene_ )
		[self performSelector:@selector(setNextScene)];
	
	glPushMatrix();
	
	[self applyOrientation];
	
	// By default enable VertexArray, ColorArray, TextureCoordArray and Texture2D
	CC_ENABLE_DEFAULT_GL_STATES();
    
	/* draw the scene */
	[runningScene_ visit];
    
    Prism::theDirector()->drawScene();
	
	/* draw the notification node */
	[notificationNode_ visit];
    
	if( displayFPS_ )
		[self performSelector:@selector(showFPS)];
	
#if CC_ENABLE_PROFILERS
	[self showProfilers];
#endif
	
	CC_DISABLE_DEFAULT_GL_STATES();
	
	glPopMatrix();
	
	[openGLView_ swapBuffers];
}

@end

#endif
